// 引入安装的signalr包
// import * as signalR from '@aspnet/signalr'
const url = process.env.VUE_APP_SIGNALR_API
const signalR = require('@aspnet/signalr')
const signal = new signalR.HubConnectionBuilder().withUrl(url)
  .build()
//  const signalr = function () {
//   var hub
//   if (hub === undefined) {
//     hub = signal
//   }
//   return hub
// }
//  自动重连
async function start() {
  try {
    await signal.start()
    console.log('connected')
  } catch (err) {
    setTimeout(() => start(), 5000)
  }
}

signal.onclose(async() => {
  await start()
})
export default {
  install: function(Vue) {
    Vue.prototype.signalr = signal
  }
}
